import request from '@/utils/request'
import Qs from 'qs'

export function categoryTree() {
	return request.get('/adminCategoty/getTotal')
}

export function listCategory(query, level) {
	if (level == 3) {
		return request.get('/adminCategoty/getThreeByPage', {
			params: {
				...query
			}
		})
	} else if (level == 2) {
		return request.get('/adminCategoty/getTwoByPage', {
			params: {
				...query
			}
		})
	} else {
		return request.get('/adminCategoty/getOneByPage', {
			params: {
				...query
			}
		})
	}
}

export function createCategory(data, level) {
	if (level == 1) {
		return request.post('/adminCategoty/addOrUpdateOne', {
			...data
		})
	} else if (level == 2) {
		return request.post('/adminCategoty/addOrUpdateTwo', {
			...data
		})
	} else {
		return request.post('/adminCategoty/addOrUpdateThree', {
			...data
		})
	}
}

export function updateCategory(data, level) {
	if (level == 3) {
		return request.post('/adminCategoty/addOrUpdateThree', {
			...data
		})
	} else if (level == 2) {
		return request.post('/adminCategoty/addOrUpdateTwo', {
			...data
		})
	} else {
		return request.post('/adminCategoty/addOrUpdateOne', {
			...data
		})
	}
}

export function deleteCategory(id, level) {
	if (level == 3) {
		return request.post('/adminCategoty/deleteThree', Qs.stringify({
			id: id,
		}))
	} else if (level == 2) {
		return request.post('/adminCategoty/deleteTwo', Qs.stringify({
			id: id,
		}))
	} else {
		return request.post('/adminCategoty/deleteOne', Qs.stringify({
			id: id,
		}))
	}
}
